<template>
  <div class="names_box">
    <HYTtile title="mingdan" />
    <van-tabs background="#f7f7f7" @click="handYear">
      <!-- title接受的是一个字符串 -->
      <van-tab :key="item.id" v-for="item in years" :title="item.year + ''">
        <van-divider>{{ item.year }}</van-divider>
        <van-row gutter="47">
          <van-col
            @click="handNav(item.recordId)"
            span="8"
            v-for="item2 in nameList"
            :key="item2.artistId"
          >
            <div class="name_item">
              <img
                :src="$filters.prefix(item2.artistPortrait)"
                class="head_img"
                alt=""
              />
              <div class="name">
                {{ item2.artistName }}
              </div>
              <div class="position">
                {{ item2.artistPosition }}
              </div>
            </div>
          </van-col>
        </van-row>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, reactive, toRefs } from "vue";
import HYTtile from "@/components/HYTtile.vue";
import { openWebUrl } from "@/utils/config";
import {
  findHistoryVoteList,
  findHistoryVoteArtistList,
} from "@/utils/apis/home";
interface YearObj {
  id: number;
}
export default defineComponent({
  name: "NameLists",
  components: {
    HYTtile,
  },

  props: {},
  setup() {
    const state = reactive({
      details: {},
      years: [] as Array<YearObj>,
      nameList: [],
    });
    const initNames = async (id: number) => {
      const res = await findHistoryVoteArtistList({
        voteId: id,
      });
      state.nameList = res.data;
    };
    onMounted(async () => {
      const years = await findHistoryVoteList();
      state.years = years.data;
      if (years.data.length !== 0) {
        initNames(years.data[0].id);
      }
    });

    const handYear = (name: string) => {
      if (state.years[Number(name)].id) {
        initNames(state.years[Number(name)].id);
      }
    };
    const handNav = (recordId: any) => {
      if (recordId) {
        window.location.href = `${openWebUrl}/personDetail?recordId=${recordId}`;
      }
    };
    return { ...toRefs(state), handYear, handNav };
  },
});
</script>
<style lang="scss" scoped>
.names_box {
  padding: 30px 20px;
  .name_item {
    display: flex;
    justify-content: center;
    flex-direction: column;
    align-content: center;
    text-align: center;
    margin-bottom: 20px;
  }
  .position {
    font-size: 11px;
    color: #666;
    @include ellipsisMultiline(2);
    width: 80px;
  }
  .name {
    font-size: 14px;
    color: #333;
    margin: 6px 0;
    width: 80px;
  }
  .head_img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    /* margin: 0 auto; */
  }
}
</style>
